﻿Imports EstoqueBLL
Public Class PecaProdutoCON
    Dim objbll As New PECABLL
    Public Tipo As String
    Public ObjP As PECABLL
    Public ObjS As ServicoBLL
    Private Sub PecaProdutoCON_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        carregagrid()
    End Sub

    Sub carregagrid()
        DGVDados.DataSource = objbll.localizarpecaservico("", 1)
        DGVDados.Refresh()
    End Sub

    Private Sub DGVDados_CellDoubleClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVDados.CellDoubleClick
        Try

            If Tipo = "ret" Then
                Dim indice As Integer = -1
                'Percorre O DataGridView Verificando a Linha selecionada
                For Each linha As DataGridViewRow In DGVDados.SelectedRows
                    If (Not linha.Cells("pro_codigo") Is Nothing) Then
                        'Guarda A Posição Selecionada
                        indice = linha.Index
                    End If
                Next
                If (indice <> -1) Then
                    If (DGVDados.Rows(indice).Cells("tipo").Value = "Peça") Then
                        ObjP = New PECABLL(Val(DGVDados.Rows(indice).Cells("codigogenerico").Value.ToString()))
                    Else
                        ObjS = New ServicoBLL(Val(DGVDados.Rows(indice).Cells("codigogenerico").Value.ToString()))
                    End If
                    Me.Close()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class